#ifndef _OCTREE_VOLUME_H
#define _OCTREE_VOLUME_H

#include "volume3D.h"
#include "octNode.h"
#include "nodePool3D.h"

#include <stack>

//#define _NO_BOUNDARY

/*
no recursive call in this class!!
*/


class octreeVolume
{
public:
	octreeVolume(volume3D *vol, int blockSize, int blockPoolDim=0);
	~octreeVolume();

	//TODO
	bool writeToFile(char* filename);//note each node will be write to individual file with their ID

	int getBlockPoolDim(); //!!pool size = blockSize*BlockPoolDim
	int setBlockPoolDim();

	void generateBlockPoolGL();
	void updateBlockPoolGL();

	//can use multi-inherentance , inherated from GLTexture
	//void generateNodePoolGL();
	//void updateNodePoolGL();

	//get
	octNode* getRoot();

	//debug
	void writeBlockPoolToFile(const char* filename);
	void writeNodePoolToFile(const char* filename);
	void write3DNodePoolToFile(const char* filename);

	//traverse octree, use by root
	void startTraverse(); //call this function to start a new octree traversal
	int next(octNode *& node); // return 0 when finish, 1 mean there is next

	void cullTreeByValue(float value);
	//debug
	void generateBlockPool(volume3D *vol, octNode* node, int &count);
	void generateNodePool(slice2D *vol, octNode* node, int &count);
	void generate3DNodePool(nodePool3D* pool, octNode* node, int &count);



private:
	int _blockSize;
	int _blockPoolDim;
	int _blockNum;
	int _nodeNum;

	int _nodePoolCluster;

	//block pool, pool of volume3D
	//blockPool[_blockPoolDim][_blockPoolDim][_blockPoolDim];
	//blockPoolElement *_blockPool;
	octNode *_root;

	//traverse
	std::stack<octNode*> _stack;
	octNode *_current;
	
	

};

#endif